//
//  LineManageViewController.m
//  Rail
//
//  Created by hychen on 2018/3/4.
//  Copyright © 2018年 Hychen. All rights reserved.
//

#import "LineManageViewController.h"
#import "LineManageTableViewCell.h"
#import "LineDetailViewController.h"
@interface LineManageViewController ()

@end

@implementation LineManageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.navigationItem addSimpleTitleView:@"线路管理"];
    
    [self.tableView.mj_header beginRefreshing];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 网络请求
- (void)refreshData {
    BMWeakSelf
    [HttpRequest loadLineListWithKeyword:@"" success:^(NSArray *array) {
        weakSelf.dataArray = array.mutableCopy;
        [weakSelf.tableView reloadData];
        [weakSelf.tableView.mj_header endRefreshing];
    } failure:^(NSString *code, NSString *msg) {
        [weakSelf.tableView.mj_header endRefreshing];
        Show_Msg_Error(msg)
    }];
}

#pragma mark - TableView
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50.f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LineModel *model = [self.dataArray objectAtIndex:indexPath.row];
    LineManageTableViewCell *cell = [LineManageTableViewCell cellWithTableView:tableView class:[LineManageTableViewCell class]];
    cell.model = model;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    LineModel *model = [self.dataArray objectAtIndex:indexPath.row];
    LineDetailViewController *vc = [LineDetailViewController new];
    vc.lineId = model.lineid;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
